<style lang="less">
  @import '../../styles/common.less';
</style>

<template>
<div class="sourcemod" style="width: 800px;">
  <Form ref="sourceData" :model="sourceData" :rules="ruleValidate" :label-width="110">
    <div class="ivu-row" >
      <div style="float: left; width: 40%;">
        <FormItem label="考试名称：" prop="scoreName">
          <Input v-model="sourceData.scoreName" placeholder="请输入考试名称"></Input>
        </FormItem>
        <FormItem label="考试分类：" prop="scoreType">
          <Input v-model="sourceData.scoreType" placeholder="请输入考试分类"></Input>
        </FormItem>
        <FormItem label="总考生人数：" prop="sourceTotalPersons">
          <Input v-model="sourceData.sourceTotalPersons" placeholder="请输入总考生人数"></Input>
        </FormItem>
      </div>
      <div style="float:left;width: 50%; height: 700px;  margin-left: 20px; padding-left: 20px; border-left: 1px #ccc solid;">
        <FormItem label="考生姓名：" prop="examineeName">
          <Input v-model="sourceData.examineeName" placeholder="请输入考生姓名"></Input>
        </FormItem>
        <FormItem label="考生班级：" prop="examineeClass">
          <Input v-model="sourceData.examineeClass" placeholder="请输入考生班级"></Input>
        </FormItem>
        <FormItem label="考生学号：" prop="examineeNumber">
          <Input v-model="sourceData.examineeNumber" placeholder="请输入考生学号"></Input>
        </FormItem>
        <FormItem label="考生身份证：" prop="examineeIdcard">
          <Input v-model="sourceData.examineeIdcard" placeholder="请输入考生身份证"></Input>
        </FormItem>
        <FormItem label="成绩评分：">
          <Select v-model="sourceData.grade" style="width:200px">
            <Option v-for="item in gradeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
        </FormItem>
        <FormItem label="备注描述：">
          <Input v-model="sourceData.remark" placeholder="请输入备注"></Input>
        </FormItem>

        <div style="margin-left: -100px">

          <FormItem>
            <Button type="primary" @click="handleSubmit('sourceData')">提交</Button>
          <Button type="ghost" @click="handleReset('sourceData')">清空</Button>
      </FormItem>
        </div>

      </div>
    </div>

  </Form>
</div>
</template>

<script>
    import moment from 'moment'
    export default {
        name: "sourcemod",
        data(){
          return{
            sourceData:{
              scoreName:'',
              scoreType:'',
              examineeName:'',
              examineeClass:'',
              examineeNumber:'',
              examineeIdcard:'',
              sourceTotalPersons:'',
              remark:'',
              grade:'优秀',
              id:0
            },
            gradeList:[
              {value:'优秀',label:'优秀'},
              {value:'良好',label:'良好'},
              {value:'合格',label:'合格'},
            ],
            ruleValidate:{
              scoreName:[
                {required: true,message:'请输入考试名称',trigger:'blur'}
              ],
              scoreType:[
                {required: true,message:'请输入考试分类',trigger:'blur'}
              ],
              examineeName:[
                {required: true,message:'请输入考生姓名',trigger:'blur'}
              ],
              examineeClass:[
                {required: true,message:'请输入考生班级',trigger:'blur'}
              ],
              examineeNumber:[
                {required: true,message:'请输入考生学号',trigger:'blur'}
              ],
              examineeIdcard:[
                {required: true,message:'请输入考生身份证',trigger:'blur'}
              ],
              sourceTotalPersons:[
                {required: true,message:'请输入总考生人数',trigger:'blur'}
              ]
            }
          }
        },
        methods:{
          handleSubmit(name){
            this.$refs[name].validate((valid) => {
              if (valid) {
                let dataArr = this.sourceData;

                console.log(dataArr);
                if(this.sourceData.id > 0){
                  this.$http.post('/school/updSource', dataArr).then(res => {
                    console.log(res);
                    this.$Message.success('提交成功!');
                    this.handleReset(name);
                  });
                }else {
                  this.$http.post('/school/addSource', dataArr).then(res => {
                    console.log(res);
                    this.$Message.success('提交成功!');
                    this.handleReset(name);
                  });
                }
              }
            })
          },
          handleReset (name) {
            this.$refs[name].resetFields();
          }
        },
      mounted () {
        console.log(this.$route.query.id);
        if(this.$route.query.id == undefined) return;
        this.$http.get('/school/getSourceById?id='+this.$route.query.id).then(res=>{
          console.log(res);
          var dt = res.data.data;
          this.sourceData.id = dt.id;
          this.sourceData.scoreName = dt.scoreName;
          this.sourceData.scoreType = dt.scoreType;
          this.sourceData.examineeName = dt.examineeName;
          this.sourceData.examineeClass = dt.examineeClass;
          this.sourceData.examineeNumber = dt.examineeNumber;
          this.sourceData.examineeIdcard = dt.examineeIdcard;
          this.sourceData.sourceTotalPersons = dt.sourceTotalPersons;
          this.sourceData.remark = dt.remark;
          this.sourceData.grade = dt.grade;

        });
      },
      created () {

      }
    }
</script>

<style scoped>

</style>
